package com.itrus.cryptorole;

import com.itrus.cert.CertNames;
import java.io.IOException;
import java.lang.reflect.Field;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.KeyStoreSpi;
import java.security.NoSuchAlgorithmException;
import java.security.PrivateKey;
import java.security.Provider;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;

public class WindowsCertStore
{
  public static final int FindByIssuerDN = 0;
  public static final int FindBySerialNumber = 1;
  public static final int FindBySubjectDN = 2;
  public static final int FindByTimeExpired = 5;
  public static final int FindByTimeNotYetValid = 4;
  public static final int FindByTimeValid = 3;
  private String issuerDN = null;
  private String serialNumber = null;
  private Hashtable subjectAttrs = null;
  private String subjectDN = null;
  private Date time4Expired = null;
  private Date time4NotYetValid = null;
  private Date time4Valid = null;
  private KeyStore windowsKeyStore = null;

  public WindowsCertStore()
    throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException
  {
    if (this.windowsKeyStore == null)
      this.windowsKeyStore = KeyStore.getInstance("Windows-MY");
    this.windowsKeyStore.load(null, null);
    fixAliases(this.windowsKeyStore);
  }

  private static void fixAliases(KeyStore paramKeyStore)
    throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, CertificateEncodingException, CertificateException
  {
    Field localField1 = paramKeyStore.getClass().getDeclaredField("keyStoreSpi");
    localField1.setAccessible(true);
    KeyStoreSpi localKeyStoreSpi = (KeyStoreSpi)localField1.get(paramKeyStore);
    Iterator localIterator;
    if ("sun.security.mscapi.KeyStore$MY".equals(localKeyStoreSpi.getClass().getName()))
    {
      Field localField2 = localKeyStoreSpi.getClass().getEnclosingClass().getDeclaredField("entries");
      localField2.setAccessible(true);
      localIterator = ((Collection)localField2.get(localKeyStoreSpi)).iterator();
    }
    while (true)
    {
      if (!localIterator.hasNext())
        return;
      Object localObject = localIterator.next();
      Field localField3 = localObject.getClass().getDeclaredField("certChain");
      localField3.setAccessible(true);
      com.itrus.cert.X509Certificate localX509Certificate = com.itrus.cert.X509Certificate.getInstance(((java.security.cert.X509Certificate[])localField3.get(localObject))[0]);
      Field localField4 = localObject.getClass().getDeclaredField("alias");
      localField4.setAccessible(true);
      localField4.set(localObject, localX509Certificate.getIssuerDNString().concat("$").concat(localX509Certificate.getHexSerialNumber()));
    }
  }

  public List getMyCertficates()
    throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException, SecurityException, IllegalArgumentException, NoSuchFieldException, IllegalAccessException, UnrecoverableKeyException
  {
    Vector localVector = new Vector();
    Enumeration localEnumeration1 = this.windowsKeyStore.aliases();
    if (!localEnumeration1.hasMoreElements())
      return localVector;
    String str1 = (String)localEnumeration1.nextElement();
    com.itrus.cert.X509Certificate localX509Certificate = com.itrus.cert.X509Certificate.getInstance((java.security.cert.X509Certificate)this.windowsKeyStore.getCertificate(str1));
    int i = 1;
    if ((this.issuerDN != null) && (!localX509Certificate.getIssuerDNString().equals(this.issuerDN)))
      i = 0;
    if ((this.subjectDN != null) && (!localX509Certificate.getSubjectDNString().equals(this.subjectDN)))
      i = 0;
    if ((this.serialNumber != null) && (!localX509Certificate.getHexSerialNumber().equals(this.serialNumber)))
      i = 0;
    if ((this.time4Valid != null) && ((!localX509Certificate.getNotBefore().before(this.time4Valid)) || (!this.time4Valid.before(localX509Certificate.getNotAfter()))))
      i = 0;
    if ((this.time4NotYetValid != null) && (!this.time4NotYetValid.before(localX509Certificate.getNotBefore())))
      i = 0;
    if ((this.time4Expired != null) && (!localX509Certificate.getNotAfter().before(this.time4Expired)))
      i = 0;
    Enumeration localEnumeration2;
    if (this.subjectAttrs != null)
      localEnumeration2 = this.subjectAttrs.keys();
    while (true)
    {
      if (!localEnumeration2.hasMoreElements())
      {
        if (i == 0)
          break;
        localVector.add(localX509Certificate);
        break;
      }
      String str2 = (String)localEnumeration2.nextElement();
      String str3 = (String)this.subjectAttrs.get(str2);
      if (!localX509Certificate.getCertSubjectNames().containsKey(str2))
        i = 0;
      else if (!localX509Certificate.getCertSubjectNames().getItem(str2).equals(str3))
        i = 0;
    }
  }

  public PrivateKey getPrivateKey(java.security.cert.X509Certificate paramX509Certificate)
    throws CertificateEncodingException, CertificateException, UnrecoverableKeyException, KeyStoreException, NoSuchAlgorithmException
  {
    com.itrus.cert.X509Certificate localX509Certificate = com.itrus.cert.X509Certificate.getInstance(paramX509Certificate);
    String str = localX509Certificate.getIssuerDNString().concat("$").concat(localX509Certificate.getHexSerialNumber());
    boolean bool = this.windowsKeyStore.isKeyEntry(str);
    PrivateKey localPrivateKey = null;
    if (bool)
      localPrivateKey = (PrivateKey)this.windowsKeyStore.getKey(str, null);
    return localPrivateKey;
  }

  public Provider getProvider()
  {
    if (this.windowsKeyStore != null)
      return this.windowsKeyStore.getProvider();
    return null;
  }

  public void setFilter(int paramInt, Object paramObject)
  {
    switch (paramInt)
    {
    default:
      return;
    case 0:
      this.issuerDN = ((String)paramObject);
      return;
    case 1:
      this.serialNumber = ((String)paramObject);
      return;
    case 2:
      this.subjectDN = ((String)paramObject);
      return;
    case 3:
      this.time4Valid = ((Date)paramObject);
      return;
    case 4:
      this.time4NotYetValid = ((Date)paramObject);
      return;
    case 5:
    }
    this.time4Expired = ((Date)paramObject);
  }

  public void setSubjectAttrFilter(String paramString1, String paramString2)
  {
    if (this.subjectAttrs == null)
      this.subjectAttrs = new Hashtable();
    this.subjectAttrs.put(paramString1, paramString2);
  }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.itrus.cryptorole.WindowsCertStore
 * JD-Core Version:    0.6.2
 */